/**
 * 
 */
package org.seckill.util.executor;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 
 * @author yue
 * 2016年6月9日 下午7:18:24
 */
public class ThreadTest {

	/**
	 * 多线程并发执行同一任务
	 * @param args
	 */
	public static void main(String[] args) {
		List<String> strList = new ArrayList<String>();
		for (int i = 0; i < 100; i++) {
            strList.add("String" + i);
        }
		int threadNum  = strList.size() < 10 ?strList.size() : 10;
		ThreadPoolExecutor executor = ThreadPoolExecutorUtil.getThreadPoolExecutor();
		long s = System.currentTimeMillis();
		for (int i = 0; i < threadNum; i++) {
			executor.execute(new PrintStringThread(i,strList,threadNum));
			/*Future<?> result = executor.submit(new PrintStringThread(i,strList,threadNum));
			try {
				Object re = result.get();
				System.out.println(re);
			} catch (InterruptedException | ExecutionException e) {
				e.printStackTrace();
			}*/
			System.out.println("=========="+ i +"==========");
		}
		System.out.println("方法执行完了................"+(System.currentTimeMillis()-s)+" 任务总数："+executor.getCompletedTaskCount());
		executor.shutdown();
	}

}
